import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

class CitywidePage extends StatelessWidget {
  const CitywidePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView(
      children: [
        _newsItem(
          "朋友让帮忙写个理发店的会员信息管理系统？",
          "不识君",
          "https://p9-passport.byteacctimg.com/img/user-avatar/c55f2905163f752caae28291297dc42f~300x300.image",
        ),
        _newsItem(
          "分布式锁：RedLock 你这锁也不包熟啊！",
          "想要进大厂的R崽",
          "https://p26-passport.byteacctimg.com/img/user-avatar/f15f29811d665c4ba6425f669863a1f3~300x300.image",
          picture: "https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/e73c1aea8cd247e484ce57ccfb401880~tplv-k3u1fbpfcp-zoom-crop-mark:1304:1304:1304:734.awebp?"
        ),
        _newsItem(
          "学不动也要学，Jetpack Compose 写一个 IM APP（二）",
          "业志陈",
          "https://p26-passport.byteacctimg.com/img/user-avatar/6019f80db5be42d33c31c98adaf3fa8c~300x300.image",
          picture: "https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/7808e798843c4742912a6502e64c962f~tplv-k3u1fbpfcp-zoom-crop-mark:1304:1304:1304:734.awebp?"
        ),
      ],
    );
  }

  Widget _newsItem(String title, String target, String avatar, {String picture = ""}) {
    return Material(
      color: Colors.white,
      child: InkWell(
        child: Container(
          height: 80.h,
          padding: EdgeInsets.only(
              top: 10.h,
              bottom: 10.h,
              left: 16.w,
              right: 16.w
          ),
          decoration: BoxDecoration(
            color: Colors.transparent,
            border: Border(
                top:
                BorderSide(color: const Color(0xffEDEDED), width: 0.5.w)),
          ),
          child: Row(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Expanded(
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(title, maxLines: 2,style: TextStyle(
                          fontSize: 15.sp,
                          height: 1.2.h,
                          overflow: TextOverflow.ellipsis, fontWeight: FontWeight.w600
                      ),),
                      Row(
                        children: [
                          CircleAvatar(
                            radius: 8.w,
                            backgroundImage: NetworkImage(
                                avatar
                            ),
                          ),
                          SizedBox(width: 4.w,),
                          Text(target, style: TextStyle(
                              fontSize: 12.sp,
                              color: const Color(0xffB2B2B2)
                          ))
                        ],
                      )
                    ],
                  )),
              picture != "" ? Container(
                width: 100.w,
                height: 80.h,
                margin: EdgeInsets.only(
                    left: 10.w
                ),
                decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.all(Radius.circular(4.w)),
                    image: DecorationImage(
                        fit: BoxFit.cover,
                        image: NetworkImage(
                          picture,
                        )
                    )
                ),
              ) : const SizedBox.shrink()
            ],
          ),
        ),
        onTap: () {
          Get.toNamed("/home/news");
        },
      ),
    );
  }
}
